package com.lanou.managerLogin.book.web.servlet;

import com.lanou.managerLogin.book.domain.Book;
import com.lanou.managerLogin.book.service.BookService;
import com.lanou.managerLogin.category.service.CategoryService;
import com.lanou.managerLogin.category.domain.Category;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/seeOneBookServlet")
public class SeeOneBookServlet extends HttpServlet {

    private BookService sbs = new BookService();
    private CategoryService cs = new CategoryService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String bid = req.getParameter("bid");
        Book book = sbs.oneBookLoad(bid);
        String cid = book.getCid();
        String cname = sbs.findCnameByCid(cid);
        List<Category> categoryList = cs.selCname();
        Category category = cs.cateCname(book.getCid());
        req.setAttribute("cid", cid);
        req.setAttribute("cname", cname);
        req.setAttribute("categoryList", categoryList);
        req.getSession().setAttribute("book", book);
        req.setAttribute("category", category);
        req.getRequestDispatcher("/adminjsps/admin/book/desc.jsp").forward(req, resp);
    }
}

